package controller

import (
	"github.com/gin-gonic/gin"
	"shop-common/library/serializer"
	"shop-common/utils/contextArgs"
	"shop-service/business"
)

type CategoryController struct {
}

// @Tags 分类接口
// @description: 分类信息列表
// @Summary 获取所有的产品分类信息，顶级分类的parentId为0,默认为顶级分类
// @function: CategoryInfo
// @Accept  json
// @Produce  json
// @Param parentId query int true "类目上级ID" default(0)
// @Success 200 {object} string "{"code":1," result":{}, "message":"操作成功", "time":1618493448}"
// @Router /category/categoryInfo [get]
func (c *CategoryController) CategoryInfo(ctx *gin.Context) {
	parentId, err := contextArgs.GetUriIntQuery(ctx, "parentId")
	if err != nil {
		serializer.Fail(ctx, err.Error())
		return
	}

	list, err := business.ServiceImpl().CategoryService.FindByParentId(ctx, uint(parentId))
	if err != nil {
		serializer.Fail(ctx, serializer.PublicQueryErr)
		return
	}

	serializer.SuccessData(ctx, "", list)
}
